package com.redbox.RedboxManagment.dao;


import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.redbox.RedboxManagment.ejb.CardPayment;

@Repository(value = "cardPaymentDao")
public class CardPaymentImp extends HibernateDaoSupport implements ICardPayment {
			
	@Transactional
	public CardPayment findById(int pId) {
		
		String queryString= "from CardPayment a where a.idCardPayment=?";
		List <CardPayment> result = getHibernateTemplate().find(queryString,pId);
		
		if (result.size() > 0) {
            return result.get(0);
        } else {
            return null;
        }   
	}


	@Transactional
	public CardPayment persistOnMerge(CardPayment pCardPayment) {
		CardPayment result = (CardPayment)getHibernateTemplate().save(pCardPayment);
		return result;
	}
	
}
